package Twice.day07.homework;

/**
 * @Author: lya
 * @Description: 本类的作用描述:饿汉模式
 *  好处:在多线程环境下,线程是安全的
 * @CreateDate: 2019/8/11
 * @Version: 1.0
 */
public class HungryMyDataSource {
    //2定义一个本类的唯一实例
    private static HungryMyDataSource instance = new HungryMyDataSource();
    //1.私有化构造 - 目的就是为了不让外界去new
    private HungryMyDataSource(){
        System.out.println("实例化....");
    }
    //定义一个静态的公开的方法来返回这个唯一实例
    public static HungryMyDataSource getInstance(){
        return instance;
    }
}
class HungryMyDataSource1{
    private static HungryMyDataSource1 instance = new HungryMyDataSource1();
    private HungryMyDataSource1(){
    }
    public static HungryMyDataSource1 getInstance(){
        return instance;
    }
}
class HungryMyDataSource2{
    private static HungryMyDataSource2 instance = new HungryMyDataSource2();
    private HungryMyDataSource2(){

    }
    public static HungryMyDataSource2 getInstance(){
        return  instance;
    }
}
class HungryMyDataSource3{
    private static HungryMyDataSource3 instance = new HungryMyDataSource3();
    private HungryMyDataSource3(){

    }
    public static HungryMyDataSource3 getInstance(){
        return  instance;
    }
}
class HungryMyDataSource4{
    private static HungryMyDataSource4 instance  = new HungryMyDataSource4();
    private HungryMyDataSource4(){

    }
    public static HungryMyDataSource4 getInstance(){
        return instance;
    }
}
class LazyMyDataSource5{
    private static LazyMyDataSource5 instance = null;
    private LazyMyDataSource5(){

    }
    public static LazyMyDataSource5 getInstance(){
        return instance == null ? instance = new LazyMyDataSource5():instance;
    }
}
